package com.lookoutthebush.companyindex.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyDate {
    private Date date;
    private static String timestampPattern = "yyyy-MM-dd HH:mm:ss";

    public MyDate() {
        date = new Date();
    }

    public MyDate(Date date) {
        this.date = date;
    }

    public MyDate(String formatStr){
        SimpleDateFormat format = new SimpleDateFormat(timestampPattern);
        Date date = null;
        try {
            date = format.parse(formatStr);
        } catch (ParseException e) {
            System.out.println("date format error");
        }
        this.date = date;
    }

    public String dateTimeString() {
        return new SimpleDateFormat(timestampPattern).format(this.date);
    }

    public String dateTimeString(String timestampPattern){
        return new SimpleDateFormat(timestampPattern).format(this.date);
    }

    public static String nowDateTimeString() {
        return new SimpleDateFormat(timestampPattern).format(new Date());
    }

    public void addMinute(Integer minute){
        long res = this.date.getTime() + minute*60*1000;
        this.date = new Date(res);
    }

    public static long diff(MyDate date, MyDate date1){
        return date.date.getTime() - date1.date.getTime();
    }
}